{include file="public/head" /}
    <script type="text/javascript" src="static/admin/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="static/admin/css/area.css" />
  <body>
      
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>后台管理</cite></a>
        <a><cite>碰一碰开门系统</cite></a>
        <a><cite>陌生人开门记录</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{:url('stranger')}">
            <!--<div id="addAddress" >
               <div class="address_input"><input class="address_input1" type="text" placeholder="请选择省市" id="shengshi" onClick="getProvinceBuy()" readonly="readonly"></div>
           </div>
           <div id="yzl" >
               
           </div>
            <div class="layui-input-inline" id="community_id" style="font-size: 20px;border:1px solid #ccc;width:150px" onclick="x_admin_show('添加小区','{:url('address')}',550,600)" >选择小区</div>
            <div class="layui-input-inline" id="group" style="font-size: 20px;border:1px solid #ccc;width:150px">选择组团</div>
            <div class="layui-input-inline" id="building" style="font-size: 20px;border:1px solid #ccc;width:150px">选择楼栋</div>
            <div class="layui-input-inline" id="unit" style="font-size: 20px;border:1px solid #ccc;width:150px">选择单元</div>
            <div class="layui-input-inline" id="room" style="font-size: 20px;border:1px solid #ccc;width:150px">选择房屋</div>-->
          <div class="layui-input-inline">
            <select name="community_id" lay-filter="community_id" id="community_id">
              <option value="">所属小区</option>
              {foreach $communitylist as $name}
              <option value="{$name.id}" {if isset($community_id)}{if $community_id == $name.id}selected{/if}{/if}>{$name.community_name}</option>
              {/foreach}
            </select>
          </div>

          
          
          <input class="layui-input" placeholder="门禁名称" name="device_name" value="{if isset($device_name)}{$device_name}{/if}">

        <div class="layui-input-inline">
            <select name="device_type" lay-filter="device_type" id="device_type">
                <option value="">门禁类型</option>

                <option value="1" {if isset($device_type)}{if $device_type ==1 }selected{/if}{/if}>大门</option>
                <option value="2" {if isset($device_type)}{if $device_type == 2}selected{/if}{/if}>单元门</option>
                <option value="3" {if isset($device_type)}{if $device_type == 3}selected{/if}{/if}>梯控</option>

            </select>
        </div>
          <input class="layui-input" placeholder="姓名" name="owner_name" value="{if isset($owner_name)}{$owner_name}{/if}">
          <input class="layui-input" placeholder="电话" name="mobile" value="{if isset($mobile)}{$mobile}{/if}">
          <input class="layui-input" placeholder="开始时间" name="start_time" id="start" {if isset($start_time)}value="{$start_time}"{/if}>
          <input class="layui-input" placeholder="结束时间" name="end_time" id="end" {if isset($end_time)}value="{$end_time}"{/if}>
          
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        {if $Think.session.usertype=="0"}
<!--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        
         {/if}

        <button class="layui-btn" onclick="exportExcel('{$export}')"><i class="layui-icon"></i>批量导出</button>
        <span class="x-right" style="line-height:40px">共有数据：{$number} 条</span>
      </xblock>
      <table class="layui-table" id="table">
        <thead  style="text-align:center;">
          <tr>
<!--            <th style="width: 4%;text-align:center;">-->
<!--                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>-->
<!--            </th>-->
            <th style="text-align: center; font-size: 16px;">小区</th>
            <th style="text-align: center; font-size: 16px;">门锁名称</th>
            <th style="text-align: center; font-size: 16px;">门锁类型</th>

            <th style="text-align: center; font-size: 16px;">手机号码</th>
            <th style="text-align: center; font-size: 16px;">姓名</th>
            <th style="text-align: center; font-size: 16px;">类型</th>
            <th style="text-align: center; font-size: 16px;">user_id</th>
            <th style="text-align: center; font-size: 16px;">时间</th>

            <th style="text-align: center; font-size: 16px;">操作</th>
          </tr>
        </thead>
        <tbody style="text-align:center;">
          {foreach $list as $val}
          <tr>
<!--            <td style="text-align: center;">-->
<!--                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$val.id}'><i class="layui-icon">&#xe605;</i></div>-->
<!--            </td>-->
            <td style="text-align: center;">{$val.community_name}</td>
            <td style="text-align: center;">{$val.device_name}</td>
              <td style="text-align: center;">
                  {if $val.device_type == 1}
                  大门
                  {/if}
                  {if $val.device_type == 2}
                  单元门
                  {/if}
                  {if $val.device_type == 3}
                  梯控
                  {/if}

              </td>

            <td style="text-align: center;">{$val.mobile}</td>
            <td style="text-align: center;">{$val.name}</td>
          <td style="text-align: center;">
              {if $val.user_type == 1}
              外卖
              {/if}
              {if $val.user_type == 2}
              快递员
              {/if}
              {if $val.user_type == 3}
              访客
              {/if}
              {if $val.user_type == 4}
              送货
              {/if}
          </td>
            <td style="text-align: center;">{$val.user_id}</td>
           <td style="text-align: center;">{$val.create_time}</td>
            <td style="text-align: center;">
<!--                <a title="编辑"  onclick="x_admin_show('编辑','{:url('admin/Roominfo/roominfoEdit')}?id={$val.id}',550,600)" href="javascript:;">-->
<!--                  <i class="layui-icon">&#xe642;</i>-->
<!--                </a>-->

                
                
               {if $Think.session.usertype=="0"}


               {/if}
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div id="page">
            {$dataList->render()|raw}
        </div>
      </div>

    </div>

   
    <script>

      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
          laydate.render({
              elem: '#start' //指定元素
              ,format: 'yyyy-MM-dd HH:mm:ss'
          });

          //执行一个laydate实例
          laydate.render({
              elem: '#end' //指定元素
              ,format: 'yyyy-MM-dd HH:mm:ss'
          });
      });

       //删除
      function roominfoDelId(id, doc){
        if(confirm('删除后无法恢复，确定要删除吗?')) 
        { 
          var url = "{:url('roominfoDelId')}?id=" + id
          // console.log(url)
          $('#' + doc).attr('href', url)
        } 
          return false; 
      } 
      //批量删除
      function delAll () {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        layer.confirm('你确定要删除这'+ count + '项吗', function(){
          $.post('{:url("admin/Roominfo/roominfoDel")}', {id: str}, function(r){
            if(r.info){
              layer.msg(r.info);
                setTimeout(function (){
                 
                	window.location.reload();
                }, 700)
            }else{
              layer.msg(r.error)
               setTimeout(function (){
                 
                	window.location.reload();
                }, 700)
            }
          })
        })
      }

      //批量导出
      function exportExcel(exportid){
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        var url = "{:url('strangerExport')}?id=" + str +'&export=' + exportid
        layer.open({
          type: 2,
          title: '批量导出记录',
          shadeClose: true,
          shade: 0.8,
          area: ['80%', '95%'],
          content: url //iframe的url
        }); 
      }
      
    </script>
    <!-- 搜索 -->
    <script>
      layui.use(['form'], function() {
          var form = layui.form
          form.on('select(community_id)', function(f){
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_id: f.value, type: 1}, function(data) {
                  $('#group').html("")
                  var option = "<option value=''>所有组团</option>"
                  $('#group').append(option)
                  for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#group').append(option)
                  }
                  
                  form.render('select')
              })
              
                $('#community_id').data('community_id', f.value)
                
          })

          form.on('select(group)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_id: community_id, group: f.value, type: 2}, function(data) {
                  $('#building').html("")
                  var option = "<option value=''>所有楼栋</option>"
                  $('#building').append(option)
                  for (var i = 0; i < data.length; i++) {
                      option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                      $('#building').append(option)
                  }
                  $('#group').data('group', f.value)
                  form.render('select')
              })
          })
  
          form.on('select(building)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community

              var data_group = $('#group').data('group')
              var get_group = "<?php if (isset($group)) { echo $group;}?>"
              var group = typeof data_group === 'undefined' ? get_group : data_group

              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {building: f.value, community_id: community_id, group: group, type: 3}, function(data) {
              $('#unit').html("")
              var option = "<option value=''>所有单元</option>"
              $('#unit').append(option)
              for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#unit').append(option)
              }
              $('#building').data('building', f.value)
              form.render('select')
              })
          })
  
          form.on('select(unit)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community

              var data_group = $('#group').data('group')
              var get_group = "<?php if (isset($group)) { echo $group;}?>"
              var group = typeof data_group === 'undefined' ? get_group : data_group

              var data_building = $('#building').data('building')
              var get_building = "<?php if (isset($building)) { echo $building;}?>"
              var building = typeof data_building === 'undefined' ? get_building : data_building
      
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {unit: f.value, community_id: community_id, group: group, building: building, type: 4}, function(data) {
              $('#room').html("")
              var option = "<option value=''>所有房间</option>"
              $('#room').append(option)
              for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#room').append(option)
              }
              $('#unit').data('unit', f.value)
              form.render('select')
              })
          })
  
      })
  </script>

    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>

  </body>

</html>